package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.bean.MyRecordBean;
import flc.ast.databinding.ActivityPicPreviewBinding;
import flc.ast.utils.AppSpUtils;

public class PicPreviewActivity extends BaseAc<ActivityPicPreviewBinding> {

    public static String imgPath;

    @Override
    protected int onCreate() {
        return R.layout.activity_pic_preview;
    }

    @Override
    protected void initView() {
        mDataBinding.ivPicPreviewBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.ivComplete.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivComplete:
                startActivity(HomeActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        Glide.with(mContext).load(imgPath).into(mDataBinding.ivPicPreviewImg);
        saveRecord(imgPath);
    }

    //保存记录
    private void saveRecord(String path) {
        List<MyRecordBean> listSave = new ArrayList<>();
        listSave.add(new MyRecordBean(path,false));
        List<MyRecordBean> listSp = AppSpUtils.getCreateRecordList();
        if (listSp != null && listSp.size() > 0) {
            listSp.addAll(listSave);
            AppSpUtils.saveCreateRecordList(listSp);
        } else {
            AppSpUtils.saveCreateRecordList(listSave);
        }
    }

}